package com.springbootee;



import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CorsFilterConfiguration {
 @Bean
     public CorsFilter corsFilter(){
     UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**",buildConfig());
    return  new CorsFilter(source);
 }
 public org.springframework.web.cors.CorsConfiguration buildConfig(){
     CorsConfiguration corsConfiguration=new CorsConfiguration();
     //允许使用任何域名
    corsConfiguration.addAllowedOrigin("*");
    //允许使用任何请求头
  corsConfiguration.addAllowedHeader("*");
    //允许使用任何请求方法
     corsConfiguration.addAllowedMethod("*");
      return corsConfiguration;
 }
}
